package com.laolei.mongo;

import java.util.UUID;

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection="user-repository-3")
@CompoundIndexes({ 
	@CompoundIndex(name = "name-index", def = "{firstName : 1, lastName : 1}") 
}) 
public class User{
		
		@Id
		private String userid =UUID.randomUUID().toString();
		
		@Indexed
		private String email=UUID.randomUUID().toString();
		
		@TextIndexed
		private String description=UUID.randomUUID().toString()+UUID.randomUUID().toString()+UUID.randomUUID().toString()+UUID.randomUUID().toString()+UUID.randomUUID().toString();
		
		private String  firstName=UUID.randomUUID().toString(),lastName=UUID.randomUUID().toString();
		
		@GeoSpatialIndexed(type=GeoSpatialIndexType.GEO_2D)
		private Point point=new Point(Math.random()*180-90, Math.random()*360-180);
		
		public User() {
		}
		
		@PersistenceConstructor
		public User(String userid,String email,String  firstName,String lastName,Point point,String description) {
			this.userid=userid;
			this.point=point;
			this.firstName=firstName;
			this.lastName=lastName;
			this.email=email;
			this.description=description;
			this.point=point;
		}
		
		public String getUserid() {
			return userid;
		}

		public void setUserid(String userid) {
			this.userid = userid;
		}
		
		public Point getPoint() {
			return point;
		}

		public void setPoint(Point point) {
			this.point = point;
		}

		public String getFirstName() {
			return firstName;
		}

		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}

		public String getLastName() {
			return lastName;
		}

		public void setLastName(String lastName) {
			this.lastName = lastName;
		}

		public String getEmail() {
			return email;
		}

		public void setEmail(String email) {
			this.email = email;
		}

		public String getDescription() {
			return description;
		}

		public void setDescription(String description) {
			this.description = description;
		}

		@Override
		public String toString() {
			return "User[userid="+userid+",point="+point+"]";
		}
	}